<?php
// No direct access
defined('_JEXEC') or die;

class PricerUpdaterHelper {

	public static $extension = 'com_pricerupdater';

	public static function addSubmenu($vName) {
		JSubMenuHelper::addEntry(
			JText::_('COM_PRICER_SUBMENU_ROBOTS'),
			'index.php?option=com_pricerupdater&view=robots',
			$vName == 'robots');
		JSubMenuHelper::addEntry(
			JText::_('COM_PRICER_SUBMENU_CATEGORIES'),
			'index.php?option=com_categories&extension=com_pricerupdater',
			$vName == 'categories');
		JSubMenuHelper::addEntry(
			JText::_('COM_PRICER_SUBMENU_CATEGORY_SYNONYMS'),
			'index.php?option=com_pricerupdater&view=categorysynonyms',
			$vName == 'categorysynonyms');
		JSubMenuHelper::addEntry(
			JText::_('COM_PRICER_SUBMENU_VENDOR_SYNONYMS'),
			'index.php?option=com_pricerupdater&view=vendorsynonyms',
			$vName == 'vendorsynonyms');
		JSubMenuHelper::addEntry(
			JText::_('COM_PRICER_SUBMENU_UPDATE_HISTORY'),
			'index.php?option=com_pricerupdater&view=updatehistory',
			$vName == 'updatehistory');
	}

	public static function getActions($categoryId = 0, $articleId = 0) {

		// Инициализируем переменные
		$user	= JFactory::getUser();
		$result	= new JObject;

		if (empty($articleId) && empty($categoryId)) {
			$assetName = 'com_pricerupdater';
		}

		elseif (empty($articleId)) {
			$assetName = 'com_pricerupdater.category.'.(int) $categoryId;
		}

		else {
			$assetName = 'com_pricerupdater.product.'.(int) $articleId;
		}

		$actions = array('core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.own', 'core.edit.state', 'core.delete');

		foreach ($actions as $action) {
			$result->set($action,	$user->authorise($action, $assetName));
		}

		return $result;
	}
}
